home *** CD-ROM | disk | FTP | other *** search
- Path: nntp.atlanta.com!usenet
- From: cam03@cppccam03.homedepot.com (Chuck Mattern)
- Newsgroups: comp.lang.c
- Subject: passing of pointers
- Date: 21 Feb 1996 23:47:56 GMT
- Organization: Internet Atlanta
- Message-ID: <4ggavc$f4u@nntp.atlanta.com>
- NNTP-Posting-Host: 151.140.22.53
- X-Newsreader: knews 0.9.5
-
- I'm stumped here and know this is probably a newbie sort of question
- but I'll ask anyway. I am writing a port utilization accounting tool
- and several points I need to pass a pointer to an element of a linked
- list of structures to another function. This is being done on hp-ux
- 9.04 with their stock cc. I'm using hp's xdb for debugging. I have a
- function called release that rolls some numbers around. I'm trying to
- pass it a pointer to the element of the linked list that I want to
- manipulate and from the inside of the function in question I can see
- that the values are all correct ant that the are updated however the
- address of the pointer is wrong and only the values pointed to by the
- pointer which is internal to this function are updated. I call the
- function like this:
-
- release(maxtime, *p); /* this p is local to the calling function and at
- the time of this invocation is equal to *tty
- which is the head of the list */
-
- The function looks like this:
-
- release(t, p)
- time_t t; /* relative time passed from calling function */
- struct ttys *p;
- {
- if (p->cur.unum < 1) /* no one logged in here, we really shouldn't call*/
- return; /* release if there's not a login but ... */
- p->usr[p->cur.unum].logtime += (t - p->cur.in); /* increment the
- total login time */
- p->usr[p->cur.unum].logins++;
- p->cur.unum = 0;
- p->cur.in = 0; /* log out */
- }
-
- At the end of this function I use xdb to print out the values at the other end of the pointers and get this:
-
- >p *tty
- 0x400037d0 struct ttys {
- line = "tty7p11";
- cur = struct user {
- unum = 7;
- in = 823671052;
- };
- usr = 0x400037e4;
- nxt = 00000000;
- }
- >p *p
- 0x7b033a2c struct ttys {
- line = "tty7p11";
- cur = struct user {
- unum = 7;
- in = 823671052;
- };
- usr = 0x7b033a40;
- nxt = 00000000;
- }
-
- Basically *tty is untouched, *p has been but it will go away at the
- end of this function. Does *p need to be global? Should I just pass
- the string contained in p->line ( which should be unique ) and let the
- release function traverse the list searching for it?
-
- Your assistance and comment are appreciated.
-
- Chuck
-
- BTW, If any of this looks familiar the basic concept was lifted from a
- program called sac which runs on linux, any bugs are mine of course
- since the other program actually works ;->.
-
- --
- Chuck Mattern "That which does not kill us, makes us stronger.."
- cmattern@homedepot.com -Friedrich Nietzsche-
- 2727 Paces Ferry Rd.
- Atlanta, GA 30339
-
-
-